package com.newoffen.com.method;

import com.aventstack.extentreports.ExtentTest;
import com.newoffen.com.listener.ExtentTestNGITestListener;
import org.openqa.selenium.NoSuchElementException;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import com.newoffen.com.page.PlatformPageElement;

public class PlatformElementMethod extends PlatformPageElement {
    ExtentTestNGITestListener el = new ExtentTestNGITestListener();
    ExtentTest log = el.getlog();
    public void sendUsername(String username){
        log.info("输入用户名");
        input_username.click();
        input_username.clear();
        input_username.sendKeys(username);
    }
    public void sendPasswd(String passwd){
        log.info("输入密码");
        input_passwd.click();
        input_passwd.clear();
        input_passwd.sendKeys(passwd);
    }
    public void sendCode(String code){
        log.info("输入验证码");
        input_code.click();
        input_code.clear();
        input_code.sendKeys(code);
    }
    public void clickBtnOK(){
        log.info("点击确定按钮");
        btn_login.click();
    }
    public void clickPlat(){
        log.info("选择平台");
        platform.click();
    }
    public void storeList(){
        log.info("点击药店菜单");
        menu_store.click();
    }

    public void store_search(String storeName,String salesclerkName){
        log.info("搜索");
        input_storeName.click();
        input_storeName.sendKeys(storeName);
        input_salesclerkName.click();
        input_salesclerkName.sendKeys(salesclerkName);
        btn_search.click();
    }
    public void update_store(){
        log.info("点击药店编辑按钮");
        updateStore.click();
    }
    public void save_store(){
        log.info("点击药店保存按钮");
        btn_save.click();
    }
    public void settlement(){
        log.info("查看结算列表");
        settlement.click();
        bill.click();
    }
    public void goods_List(){
        log.info("进入商品列表");
        menu_goods.click();
        menu_goodsList.click();
    }
    public void goods_search(String goodsName,String goodsID,String goodsType){
        log.info("商品搜索");
        input_goodsName.sendKeys(goodsName);
        input_goodsID.sendKeys(goodsID);
        input_goodsType.sendKeys(goodsType);
        btn_goodsSearch.click();
    }
    public void goods_update(){
        log.info("商品编辑");
        updateGoods.click();
    }
    public void goods_save(){
        log.info("商品信息保存");
        goodssave.click();
    }
    public void orderList(){
        log.info("进入订单列表");
        menu_order.click();
        menu_orderList.click();
    }
    public void orderSearch(String searchType,String orderNo,String payType,String paySource){
        log.info("快递订单搜索");
        input_searchType.sendKeys(searchType);
        input_orderNo.sendKeys(orderNo);
        input_payType.sendKeys(payType);
        input_paySource.sendKeys(paySource);
        btn_search_order.click();
    }

    public void rxList(){
        log.info("处方审核");
        menu_RX.click();
    }
    public void RXSearch(String rxNo){
        log.info("搜索处方审核订单");
        input_rxNo.sendKeys(rxNo);
        btn_RXSearch.click();
    }
    public void afterSaleList(){
        log.info("售后维权");
        menu_afterSale.click();
    }
    public void saleOrderSearch(String saleNo){
        log.info("快递订单搜索");
        input_saleNo.sendKeys(saleNo);
        btn_saleSearch.click();
    }
    public void recipeList(){
        log.info("查看处方笺列表");
        menu_health.click();
    }
    public void recipeSearch(String state){
        log.info("处方笺搜索");
        input_recipeState.sendKeys(state);
        btn_recipeSearch.click();
    }
    public void reportList(){
        log.info("查看体检报告列表");
        menu_report.click();
    }
    public void reportSearch(String name){
        log.info("体检报告搜索");
        input_reportName.sendKeys(name);
        btn_reportSearch.click();
    }
    public void viewDetail(){
        log.info("体检报告搜索");
        btn_reportDetail.click();
    }





    public void waitElement(WebDriver driver, WebElement webelement) throws Exception {
//        try{
        WebDriverWait wait = new WebDriverWait(driver, 10);
        wait.until(ExpectedConditions.elementToBeClickable(webelement));
//        }catch (Exception e){
//            log.info("报错信息！元素："+webelement+" 没有找到");
//            e.printStackTrace();
//        }
    }
    //    通用判断元素是否存在
    public boolean doesWebElementExist(WebElement webElement) {
        try {
            return webElement.isDisplayed();
        } catch (NoSuchElementException e) {
            return false;
        }
    }
    //滑动鼠标到指定元素
    public void moveToElement(WebDriver driver,WebElement webElement){
        log.info("移动鼠标到元素"+webElement);
        Actions action=new Actions(driver);
        action.moveToElement(webElement).perform();
    }
    //操作网页前进、后退、刷新
    public void refresh(WebDriver driver){
        log.info("刷新当前页面");
        driver.navigate().refresh();
    }
    public void back(WebDriver driver){
        log.info("回退到上一页面");
        driver.navigate().back();
    }
    public void forward(WebDriver driver){
        log.info("前进到上一页面");
        driver.navigate().forward();
    }
//    public void switchWindow(WebDriver driver){
//        String parentHandle=driver.getWindowHandle();
//        Sethandles=driver.getWindowHandles();
//
//        String currenWindow = driver.getWindowHandles ();
//        driver.switchTo().window(a);
//    }
}
